Skip to content

Conversation

@shivkr6
Copy link
Contributor

@shivkr6 shivkr6 commented Oct 3, 2025

Depends on #11

Implemented the following types required to successfully construct a conntrack get request:

  • iptuple
  • protoinfo
  • protoinfotcp
  • prototuple
  • tcp_flags
  • tuple

Also wrote tests to construct a conntrack get and dump request.

@shivkr6 shivkr6 force-pushed the conntrack-get branch 4 times, most recently from eaaa88f to c7c6939 Compare October 7, 2025 10:42
@shivkr6 shivkr6 force-pushed the conntrack-get branch 2 times, most recently from f89a9cd to e171eca Compare October 19, 2025 17:04
@shivkr6 shivkr6 requested a review from cathay4t October 19, 2025 17:05
@shivkr6
Copy link
Contributor Author

shivkr6 commented Oct 19, 2025

Thanks for the review @cathay4t . I've updated the tests and moved the conntrack constants to be private as you suggested.

I noticed the nflog module still exposes public constants. Let me know if you want those refactored as well to hide the implementation details. Happy to do it in a follow up PR.

I also added one more conntrack get UDP IPv6 test.

Copy link
Member

@cathay4t cathay4t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All public data type should be protected by #[non_exhaustive] unless you are sure it will never changes in the future of Linux kernel.

Copy link
Member

@cathay4t cathay4t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The netlink-packet-routes has changed nlas to attributes for better understanding.

The nlas is for hard for new developer to understand.

Implemented the following attributes required to successfully construct a conntrack get request:
* iptuple
* protoinfo
* protoinfotcp
* prototuple
* tcp_flags
* tuple

Signed-off-by: Shivang K Raghuvanshi <shivangraghuvanshi2005@gmail.com>
@shivkr6 shivkr6 force-pushed the conntrack-get branch 2 times, most recently from 2d15bc3 to f002e81 Compare October 28, 2025 08:00
This refactors the crate to use type-safe enums for netfilter subsystems and message types, for a safer and more idiomatic API.

- Introduces a `Subsystem` enum to replace raw `u8` identifiers for `NfLog` and `Conntrack` subsystems.

- Introduces `NfLogMessageType` and `ConntrackMessageType` enums to provide type safety for messages within each subsystem.

- Makes the top-level `NetfilterMessage::message_type()` function private to guide users towards the safer pattern of matching on `NetfilterMessageInner`.

- Updates the internal parsing logic in `buffer.rs` to use the new `Subsystem` enum.

Signed-off-by: Shivang K Raghuvanshi <shivangraghuvanshi2005@gmail.com>
@shivkr6
Copy link
Contributor Author

shivkr6 commented Oct 28, 2025

Hi @cathay4t, I've addressed all of the feedback.

NOTE:
In the tests, you'll see we're manually building the message type from enums because we have removed netlink message header from raw: Vec<u8> which contains the message type.
I.e.,

    let message_type = ((u8::from(Subsystem::Conntrack) as u16) << 8)
        | (u8::from(ConntrackMessageType::Get) as u16);

a normal crate user would not have to do this type of stuff.

}

const NFNL_SUBSYS_CTNETLINK: u8 = libc::NFNL_SUBSYS_CTNETLINK as u8;
const NFNL_SUBSYS_ULOG: u8 = libc::NFNL_SUBSYS_ULOG as u8;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use libc constant, use hard coded number instead. I have to check libc code and kernel code to make sure your are correct.

impl From<u8> for Subsystem {
fn from(value: u8) -> Self {
match value {
NFNL_SUBSYS_ULOG => Self::NfLog,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A proper explanation command is required for this inconsistency on naming.


#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum ConntrackNla {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about ContrackAttribute like LinkAttribute in netlink-packet-route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants